package com.sunwayhorizo.health.hl7.rim;

import com.sunwayhorizo.health.hl7.common.DataTypeUtil;
import com.sunwayhorizo.health.hl7.common.Hl7Exception;
import com.sunwayhorizo.health.hl7.datatypes.CE;
import com.sunwayhorizo.health.hl7.persistent.RimCoreActCdSets;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.NamedQuery;

import static com.sunwayhorizo.health.hl7.vocabulary.ActCdSetCode.*;


@Entity
@NamedQuery(name = "FinancialContract.findAll", query = "select o from FinancialContract o")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorValue("FCNTRCT")
public class FinancialContract extends Act implements Serializable {
    
//    public CE paymentTermsCode;
    
    public FinancialContract() throws Hl7Exception {
    }
    
    

    public void setPaymentTermsCode(CE ce) {
    	if(null != ce && ce.codeSystemEnName()!=null && ce.codeName()!= null)
        {
            setRimCoreActCdSets(ce, FCPAYMENTTERMSCDSETCODE);
        }
        else
        {
            this.setFcPaymentTermsEtsId(ce.code().toString());
        }
    }

    public CE getPaymentTermsCode() throws Hl7Exception {
    	if (this.getFcPaymentTermsEtsId().equals(FCPAYMENTTERMSCDSETCODE.toString()))
        {
            for (RimCoreActCdSets actCdSets : this.getActCdSetsList())
            {
                if (this.getFcPaymentTermsEtsId().equals(actCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(actCdSets);
                }
            }            
        }
        else
            return DataTypeUtil.getCE(this.getFcPaymentTermsEtsId()); 
        return null;
    }
    
    //FinancialContract  
        @Column(name = "FC_PAYMENT_TERMS_ETS_ID")    
        protected String fcPaymentTermsEtsId = FCPAYMENTTERMSCDSETCODE.toString();
        
    protected String getFcPaymentTermsEtsId() {
        return fcPaymentTermsEtsId;
    }

    protected void setFcPaymentTermsEtsId(String fcPaymentTermsEtsId) {
        this.fcPaymentTermsEtsId = fcPaymentTermsEtsId;
    }

}
